﻿using DataServices;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace LFWeb3.Controllers
{
    public class AdminLoginController : Controller
    {
        //
        // GET: /AdminLogin/


        DaoAdminLogin adminLoginDao = new DaoAdminLogin();


        /*---------------------以下后台管理页面--------------------- */
        public ActionResult Index()
        {
            return View();
        }


        /*----------请求操作--------- */
        public JsonResult CheckLogin(string UserName, string Password)
        {
            try
            {
                if (adminLoginDao.CheckLogin(UserName, Password))
                {
                    Session["UserName"] = UserName;
                    return Json("success", JsonRequestBehavior.AllowGet);
                }
                else
                {
                    return Json("failed", JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception ex)
            {
                return Json(ex.Message, JsonRequestBehavior.AllowGet);
            }
        }


        public JsonResult ModifyPassword(string UserName, string Password)
        {
            try
            {
                adminLoginDao.ModifyPassword(UserName, Password);
                return Json("success", JsonRequestBehavior.AllowGet); 
            }
            catch (Exception ex)
            {
                return Json(ex.Message, JsonRequestBehavior.AllowGet);
            }
        }

    }
}
